package interaction.game;

import java.util.Random;

import gifAnimation.Gif;
import processing.core.PApplet;
import processing.core.PFont;
import processing.core.PImage;
import processing.core.PVector;

public class GameObjectFactory {
	private String baseImagePath = "interaction/game/images/";
	private String baseDataPath = "interaction/game/data/";
	private PApplet applet;
	private Random random = new Random();
	
	public GameObjectFactory(PApplet applet)
	{
		this.applet = applet;
	}
	
	public String getDataPath(String data)
	{
		return baseDataPath + data;
	}
	
	public String getImagePath(String image)
	{
		return baseImagePath + image;
	}
	
	public PFont getScoreFont()
	{
		return applet.loadFont(getDataPath("Palatino-Bold-40.vlw"));
	}
	
	public ScoreItem createScores(Hero hero)
	{
		return new ScoreItem(getScoreFont(), hero);
	}
	
	public Hero createHero()
	{
		return new Hero(getHeroAnimation(), new PVector(100, 345));
	}
	
	public Animation getHeroAnimation()
	{
		return new Animation(Gif.getPImages(applet, getImagePath("uusi_panda2.gif")));
	}
	
	public PImage loadImage(String path)
	{
		return applet.loadImage(getImagePath(path));
	}
	
	public GameObjectCollection createFoliage(final Hero hero)
	{
		return new GameObjectCollection() {{
			add(new RandomForegroundItem(loadImage("lopulliset_bambut1.png"), new PVector(50, 200), new PVector(), 800, hero));
			add(new RandomForegroundItem(loadImage("lopulliset_bambut2.png"), new PVector(800, 200), new PVector(), 1400, hero));
			add(new RandomForegroundItem(loadImage("lopulliset_bambut3.png"), new PVector(1200, 200), new PVector(), 1700, hero));
		}};
	}
	
	public GameObjectCollection createTraps(final Hero hero)
	{
		return new GameObjectCollection() {{
			add(new DeathItem(loadImage("piikkipuska1.png"), new PVector(4200, 430), new PVector(), 4200, hero));
			add(new DeathItem(loadImage("piikkipuska1.png"), new PVector(6000, 430), new PVector(), 6000, hero));
		}};
	}
	
	public GameObjectCollection createCollectibleItems(final Hero hero, final ScoreItem scores)
	{
		return new GameObjectCollection() {{
			add(new CollectibleItem(loadImage("pinkki_hedelma.png"), loadImage("tyhja.png"), new PVector(400, 250), new PVector(), 1200, hero, scores));
			add(new CollectibleItem(loadImage("pinkki_hedelma.png"), loadImage("tyhja.png"), new PVector(450, 270), new PVector(), 2000, hero, scores));
		}};
	}
	
	public GameObjectCollection createEarth(final Hero hero)
	{
		return new GameObjectCollection() {{
			// Two textures to loop around
			add(createEarthSlice(0, hero));
			add(createEarthSlice(800, hero));
			// Two textures in between to cover floating point errors
			add(createEarthSlice(400, hero));
			add(createEarthSlice(1200, hero));
		}};
	}
	
	public GameObject createEarthSlice(int offset, Hero hero)
	{
		return new ForegroundItem(loadImage("lopullinen_maa.png"), new PVector(offset, 0), new PVector(), 800, hero);
	}

	public GameObjectCollection createBackground() {
		return new GameObjectCollection() {{
			add(new BaseGameObject(loadImage("vaalea_aurinko.png"), new PVector(), new PVector()));
			add(new BaseGameObject(loadImage("vaaleat_vuoret1.png"), new PVector(), new PVector()));
		}};
	}
}
